package com.sumi.erp.controller;

import com.sumi.common.annotation.Log;
import com.sumi.common.core.controller.BaseController;
import com.sumi.common.core.domain.AjaxResult;
import com.sumi.common.core.page.TableDataInfo;
import com.sumi.common.enums.BusinessType;
import com.sumi.common.utils.poi.ExcelUtil;
import com.sumi.erp.domain.BaseProduct;
import com.sumi.erp.service.IBaseProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 产品基本信息Controller
 * 
 * @author fgf67@163.com
 * @date 2024-06-20
 */
@RestController
@RequestMapping("/product/product")
public class BaseProductController extends BaseController
{
    @Autowired
    private IBaseProductService baseProductService;

    /**
     * 查询产品基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('product:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseProduct baseProduct)
    {
        startPage();
        List<BaseProduct> list = baseProductService.selectBaseProductList(baseProduct);
        return getDataTable(list);
    }

    /**
     * 导出产品基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('product:product:export')")
    @Log(title = "产品基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseProduct baseProduct)
    {
        List<BaseProduct> list = baseProductService.selectBaseProductList(baseProduct);
        ExcelUtil<BaseProduct> util = new ExcelUtil<BaseProduct>(BaseProduct.class);
        util.exportExcel(response, list, "产品基本信息数据");
    }

    /**
     * 获取产品基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:product:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(baseProductService.selectBaseProductById(id));
    }

    /**
     * 新增产品基本信息
     */
    @PreAuthorize("@ss.hasPermi('product:product:add')")
    @Log(title = "产品基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseProduct baseProduct)
    {
        return toAjax(baseProductService.insertBaseProduct(baseProduct));
    }

    /**
     * 修改产品基本信息
     */
    @PreAuthorize("@ss.hasPermi('product:product:edit')")
    @Log(title = "产品基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseProduct baseProduct)
    {
        return toAjax(baseProductService.updateBaseProduct(baseProduct));
    }

    /**
     * 删除产品基本信息
     */
    @PreAuthorize("@ss.hasPermi('product:product:remove')")
    @Log(title = "产品基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(baseProductService.deleteBaseProductByIds(ids));
    }
}
